<?php
class ColleagesController extends AppController
{
     var $name='Colleages';
     var $uses = array('Colleage','Attachment','Codetype','Constant','Project','ProCvalue','IndustryCvalue','CgNew','CgDev','CgPerson','CgPatent','CgProduct','CgEquipment','CgLab','CgResearchcenter','CgDemand','CgTestplatform','CgAptitude','CgAwardproject');     
     var $helpers=array('Pagination','Html','Javascript','Form','Fck','Str','Action','Accp');
     var $components = array ('Pagination');
     var $layout='hindex';
                 
     //首页展示内容
     function index()
     {
        $this->Session->delete('colleageid');
        $this->Session->delete('colleagename');
     
        $dormitoryleases = array();
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/index/';
        $urlcount=0;
        $where = "";
        $keyword = "";
        
        if(!empty($_GET['keyword']))
        {
                $keyword=$_GET['keyword'];
                $where.="(Colleage.colleage_name like '%".urldecode($keyword)."%') and ";
        }
        
        $where .= "Colleage.is_deleted = '0'";

        $urlcount = $this->Colleage->findCount($where);
         if(!empty($_GET['keyword']))
         {
            $this->Session->setFlash('共检索出'.$urlcount.'条记录');
        }
        
        $paging['total'] =$urlcount;
        $showpage=0;
        $colleages = array();
        
        $all_colleages = $this->Colleage->findAll($where,"Colleage.colleage_name");
        
        if ($paging['total'] > 0) {
                    list ($order, $limit, $page) = $this->Pagination->init("", $paging);
                    $colleages=$this->Colleage->findAll($where,"`Colleage`.`id`, `Colleage`.`colleage_name`,  `Colleage`.`email`, `Colleage`.`describe`,  `Colleage`.`direction`,`Colleage`.`link`,`Colleage`.`contact`, `Colleage`.`tel`","Colleage.modified desc",$limit,$page);
                    if($urlcount>$pagesize)
                    {
                        $showpage=1;
                    }
        }
        $this->set(compact('all_colleages','colleages','showpage','keyword'));
     }
     
    function checkusermail($obj,$accp,$index)
    {
        $email="";
        $umail="";
        if($index=="colleage")
        {
            $email=$obj["Colleage"]["email"];
        }
        if($index=="colleageuser")
        {
            $email=$obj["CgPerson"]["email"];
        }
        $umail=$obj["User"]["uemail"];
        $flag=true;
        if($umail!=""){
            if($email!=$umail){
                $flag=true;
            }else{
                $flag=false;
            }
        }
        if($flag){
            $data=array("checkemail"=>$email);
            $objusers=$accp->accpactionuser($data);
            if($objusers["isflag"]=="1"){
                $this->Session->setFlash('邮箱已经注册过','default',array('class' => 'info_error_alert'));
                $this->redirect($this->referer());
                exit();
            }
        }
        if($index=="colleage"){
            $cid=$obj["Colleage"]["id"];
            if($cid){
                $name=$obj["Colleage"]["contact"];
                $mobile=$obj["Colleage"]["tel"];
                $address=$obj["Colleage"]["address"];
                $data=array("saveuserbymail"=>$umail,"name"=>$name,"email"=>$email,"mobile"=>$mobile,"address"=>$address);
                $accp->accpactionuser($data);
            }
        }
        if($index=="colleageuser"){
            $pid=$obj["CgPerson"]["id"];
            if($pid){
                $name=$obj["CgPerson"]["name"];
                $mobile=$obj["CgPerson"]["tel"];
                $address=$obj["CgPerson"]["address"];
                $data=array("saveuserbymail"=>$umail,"name"=>$name,"email"=>$email,"mobile"=>$mobile,"address"=>$address);
                $accp->accpactionuser($data);
            }
        }
    }
     //编辑高校的信息
     function editcolleageinfo($id = null)
     {
        $logo = array();
        if($id)
        {
            $objcolleage = $this->Colleage->findById($id);
            if(empty($objcolleage)){
                $this->redirect('/users/login');
                exit();
            }
            $this->Session->write('colleageid', $id);
            $this->Session->write('colleagename', $objcolleage["Colleage"]["colleage_name"]);
            $where="CgDev.colleage_id='$id' and CgDev.is_deleted='0'";
            $cgdev=$this->CgDev->findAll($where,"CgDev.id");
            if($cgdev)
            {
                $this->Session->write('cdid', $cgdev[0]["CgDev"]["id"]);
            }
            else
            {
                $this->Session->write('cdid', '');
            }
            $this->data = $objcolleage;
            $found_time = $objcolleage["Colleage"]["found_time"];
            if($found_time)
                $this->data["Colleage"]["found_time"]=date("Y-m-d",strtotime($found_time));
            $logo = $objcolleage["Logo"];
        }
        else
        {
            if(!empty($this->data))
            {
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                $this->checkusermail($this->data,$accp,"colleage");

                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                /*提交图片 开始*/
                if(!empty($_FILES['LogoPicture']))
                {
                    $uploads=$_FILES['LogoPicture'];
                    $dirpath="upload/files/";
                    if($uploads["name"][0])
                    {
                        $file_path=$actionf->upload_file($uploads,$dirpath,0,1);
                        $objAttachments["Attachment"]["file_name"] = $uploads["name"][0];
                        $objAttachments["Attachment"]["file_path"] = $dirpath.$file_path;
                        $this->Attachment->save($objAttachments);
                        $aids=$this->Attachment->getLastInsertId();
                        $this->data["Colleage"]["logo_id"]=$aids;
                        $this->Attachment->id=null;
                    }
                }
                /*提交图片 结束*/
                
                $objcolleage = $this->Colleage->save($this->data);
                $colleage_id=$this->data["Colleage"]["id"];
                if(empty($colleage_id))
                {
                    $colleage_id=$this->Colleage->getLastInsertId();
                    $contact = 	$objcolleage["Colleage"]["contact"];
                    $mobile = $objcolleage["Colleage"]["tel"];
                    $email = $objcolleage["Colleage"]["email"];
                    $groupid=$this->Constant->ColleageGroupId;	
                    $data=array("name"=>$contact,"email"=>$email,"mobile"=>$mobile,
                    "cgid"=>$colleage_id,
                    "usertype"=>"4","groupid"=>$groupid);
                    $regdata=$accp->accpreg($data);		
                    $data=array("guid"=>$colleage_id,"event"=>"addcolleageinfo","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }
                else
                {					
                    $data=array("guid"=>$colleage_id,"event"=>"editcolleageinfo","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }
                $this->Session->setFlash("高校信息保存成功");
                $this->Session->write('colleageid', $colleage_id);
                $this->Session->write('colleagename',$this->data["Colleage"]["colleage_name"]);
                if(empty($colleage_id))
                {
                    $colleage_id = $this->Colleage->getLastInsertId();
                    $this->Session->write('colleageid', $colleage_id);
                    $this->Session->write('colleagename',$this->data["Colleage"]["colleage_name"]);
                    $this->quote($id); 
                }
                else
                {
                    $this->quote($id);
                }
            }
        }
          $this->set(compact('id','logo'));		     				     		
    }
         
    function quote($id)
    {						     				   
        if($this->data["Colleage"]["person"])
        {
            $this->redirect(array('action' => 'editperson',$this->CgPerson->id));														
        } 
        if($this->data["Colleage"]["cgpatents"])
        {
            $this->redirect(array('action'=>'editcgpatent'));						
        }
        else if($this->data["Colleage"]["equipments"])
        {
            $this->redirect(array('action'=>'editequipment'));		
        }
        else if($this->data["Colleage"]["researchcenters"])
        {
            $this->redirect(array('action'=>'editresearchcenter'));		    
        }
        else
        {	
            $this->redirect(array('action' => 'index'));
        }	
    }
         
     //显示高校的信息
     function showcolleageinfo($id = null)
     {
        $this->editcolleageinfo($id);
     }
     
     //删除高校的信息
     function delcolleageinfo($id = null,$email)
     {
        $this->Colleage->id = $id ;
        $this->Colleage->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delcolleageinfo","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        
        //删除accp用户
        $objusers=$this->Session->read('AllUserList');
        $email=base64_decode($email);
        classRegistry::init("Company")->deleteAccpUser($objusers,$accp,$email);
        
        $this->Session->setFlash("高校信息删除成功");
        $this->redirect(array('action'=>'index'));
     }
         
         
                                                                                                                                    /*高校新闻部分  开始*/
     //新闻首页展示内容
     function news()
     {
        $colleageid = $this->Session->read('colleageid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/news/';
        $urlcount=0;
            
        $where = "CgNew.is_deleted='0'";
                    
         if($colleageid)
        {
                $where.="and CgNew.colleage_id='$colleageid'";
        }
        $urlcount = $this->CgNew->findCount($where);
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        $news = array();
        if ($paging['total'] > 0) 
        {
                list ($order, $limit, $page) = $this->Pagination->init("", $paging);
                $news=$this->CgNew->findAll($where,null, "CgNew.created desc",$limit, $page);
                if($urlcount>$pagesize)
                {
                    $showpage=1;
                }
        }
        $this->set(compact('news','showpage'));
     }
     
     //编辑新闻
     function editnews($id = null)
     {
        $this->set(compact('id'));
        if($id)
        {
            $objnews = $this->CgNew->findById($id);
            $this->data = $objnews;
        }
        else
        {
             if(!empty($this->data))
             {
                $this->CgNew->save($this->data);
                $gid=$this->data["CgNew"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($gid)){
                    $gid=$this->CgNew->getLastInsertId();					
                    $data=array("guid"=>$gid,"event"=>"addnews","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$gid,"event"=>"editnews","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }
                $this->Session->setFlash("高校研发新闻信息保存成功");
                $this->redirect(array('action'=>'shownews',$this->CgNew->id));
             }
        }
     }
     
     //显示具体的新闻
     function shownews($id)
     {
        $this->editnews($id);
     }
     
     //删除新闻
     function delnews($id)
     {
        $this->CgNew->id = $id;
        $this->CgNew->saveField("is_deleted",'1');		     		
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delnews","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("研发新闻删除成功");
        $this->redirect(array('action'=>'news'));
     }
                                                                                                                                             /*高校新闻部分  结束*/
                 
     //高校发展情况部分
     function editdev($flag = null)
     {
        $cdid=$this->Session->read('cdid');
        if(!empty($cdid) && empty($flag))
        {
            $this->Session->write('cdid',$cdid);
            $this->data=$this->CgDev->findById($cdid);
        }
        else
        {
            if(!empty($this->data))
            {
                $colleageid=$this->Session->read('colleageid');
                if($colleageid)
                {
                    $this->data["CgDev"]["colleage_id"]=$colleageid;
                }
                $objcgdev=$_POST;
                $cgdevs=array();
                foreach ($objcgdev as $key=>$cgdev)
                {
                    if($key!="_method" && $key!="data" )
                    {
                        $this->data["CgDev"][$key]=$_POST[$key];
                    }
                }
                $this->CgDev->save($this->data);
                $gid=$this->data["CgDev"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($gid)){
                    $gid=$this->CgDev->getLastInsertId();					
                    $data=array("guid"=>$gid,"event"=>"adddev","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$gid,"event"=>"editdev","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }
                $this->Session->setFlash('高校信息保存成功');
                if(empty($this->data["CgDev"]["id"]))
                {
                    $cdid=$this->CgDev->getLastInsertId();
                }
                else
                {
                    $cdid=$this->data["CgDev"]["id"];
                }
                $this->Session->write('cdid',$cdid);
                $this->redirect(array('action' => 'editdev'));
            }
        }
     }
                
                                                                                                /*高校人员情况 开始*/
    //根据不同类型的人统计人数
    function getpersontypecount($colleageid)
    {
        $colleage_titles=$this->Codetype->getCValues($this->Constant->ColleageTitle);
        $colleage_titles = array_splice($colleage_titles, 1);
        $colleage_title_count = array();
        $personcount=0;
        $i=0;
        foreach ($colleage_titles as $key=>$colleage_title)
        {
            $where="CgPerson.title='$key'";
            if($colleageid){
                $where.=" and CgPerson.colleage_id='$colleageid'";
            }
            $where.=" and CgPerson.is_deleted='0'";
            $count=$this->CgPerson->findCount($where);
            $colleage_title_count[$i]["key"]=$key;
            $colleage_title_count[$i]["count"]=$count;
            $colleage_title_count[$i]["name"]=$colleage_title;
            $i++;
            $personcount+=$count;
        }
        $this->set(compact('colleage_title_count','personcount','colleage_titles'));
    }
    
    //汇总一个高校的所有人员
    function person()
    {
        $colleageid = $this->Session->read('colleageid');
        $this->getpersontypecount($colleageid);
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/person/';
        $urlcount=0;
        
        $where = "CgPerson.is_deleted='0'";
        
        if(!empty($_GET['title'])){
            $where.=" and CgPerson.title='".$_GET['title']."'";
        }
        
        if($colleageid)
        {
            $where.=" and CgPerson.colleage_id='$colleageid'";
        }
        $urlcount = $this->CgPerson->findCount($where);
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        $persons = array();
        if ($paging['total'] > 0) 
        {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $persons=$this->CgPerson->findAll($where,null, "CgPerson.created desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('persons','showpage','urlcount'));
    }
   
    //编辑高校人员
    function editperson($id = null)
    {
        $colleage_title=$this->Codetype->getCValues($this->Constant->ColleageTitle);
        $this->set(compact('colleage_title','id'));
        if($id)
        {
            $person = $this->CgPerson->findById($id);
            $this->data = $person;
        }
        else
        {
            if(!empty($this->data))
            {
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                $this->checkusermail($this->data,$accp,"colleageuser");
                    
                $objperson = $this->CgPerson->save($this->data);
                $gid=$this->data["CgPerson"]["id"];
                if(empty($gid)){
                    $gid=$this->CgPerson->getLastInsertId();
                    $colleage_id = $objperson["CgPerson"]["colleage_id"];
                    $contact = 	$objperson["CgPerson"]["name"];
                    $mobile = $objperson["CgPerson"]["tel"];
                    $email = $objperson["CgPerson"]["email"];
                    $groupid=$this->Constant->ColleageGroupId;	
                    $data=array("name"=>$contact,"email"=>$email,"mobile"=>$mobile,
                    "cgid"=>$colleage_id,
                    "usertype"=>"5","groupid"=>$groupid);
                    $regdata=$accp->accpreg($data);						
                    $data=array("guid"=>$gid,"event"=>"addperson","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$gid,"event"=>"editperson","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }
                $this->Session->setFlash("高校人员信息保存成功");
                $this->redirect(array('action'=>'showperson',$this->CgPerson->id));
            }
             $this->data["CompPerson"]["is_contact"]=0;
        }
    }
    
        
    //显示具体高校人员信息
    function showperson($id)
    {
        $this->editperson($id);
    }
    
    //删除高校人员信息
    function delperson($id = null,$email)
    {
        $this->CgPerson->id = $id;
        $this->CgPerson->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delperson","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        
        //删除accp用户
        $objusers=$this->Session->read('AllUserList');
        $email=base64_decode($email);
        classRegistry::init("Company")->deleteAccpUser($objusers,$accp,$email);
        
        $this->Session->setFlash("高校人员信息删除成功");
        $this->redirect(array('action'=>'person'));
    }
                                                                                                /*高校人员情况 结束*/
                                                                                                                                                                    /*高校成果展示区域*/
    //所有专利的汇总信息
    function cgpatents()
    {
        $colleageid = $this->Session->read('colleageid');
        $this->Session->delete('patentid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/cgpatents/';
        $urlcount=0;
        
        $where = "CgPatent.is_deleted='0'";
        if($colleageid)
        {
            $where.="and CgPatent.colleage_id='$colleageid'";
        }
        $urlcount = $this->CgPatent->findCount($where);
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        $patents = array();
        if ($paging['total'] > 0) 
        {
                list ($order, $limit, $page) = $this->Pagination->init("", $paging);
                $patents=$this->CgPatent->findAll($where,null, "CgPatent.created desc",$limit, $page);
                if($urlcount>$pagesize)
                {
                    $showpage=1;
                }
        }
        $this->set(compact('patents','showpage','urlcount'));
    }
    
    //编辑一个专利信息
    function editcgpatent($id = null)
    {
        $industrys=$this->Codetype->getCValues($this->Constant->Industry,1);//所属产业
        $this->set(compact('industrys','id'));
        $pros_cvalues=array();
        $attachments=array();
        $photo = array();
        if($id)
        {
            $objpatent = $this->CgPatent->findById($id);
            $this->Session->write('patentid',$id);
            $this->data = $objpatent;
            $this->data["CgPatent"]["authorized_time"] = date("Y-m-d",strtotime($objpatent["CgPatent"]["authorized_time"]));
            $this->data["CgPatent"]["saled_time"] = date("Y-m-d",strtotime($objpatent["CgPatent"]["saled_time"]));
            $pros_cvalues = $objpatent["pros_cvalue"];
            $attachments = $objpatent["Attachment"];
            $photo = $objpatent["Photo"];
        }
        else
        {
            if(!empty($this->data))
            {    
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                
                /*提交图片 开始*/
                if(!empty($_FILES['PatentPicture']))
                {
                    $uploads=$_FILES['PatentPicture'];
                    $dirpath="upload/files/";
                    if($uploads["name"][0])
                    {
                        $file_path=$actionf->upload_file($uploads,$dirpath,0,1);
                        $objAttachments["Attachment"]["file_name"] = $uploads["name"][0];
                        $objAttachments["Attachment"]["file_path"] = $dirpath.$file_path;
                        $this->Attachment->save($objAttachments);
                        $aids=$this->Attachment->getLastInsertId();
                        $this->data["CgPatent"]["photo_id"]=$aids;
                        $this->Attachment->id=null;
                    }
                }
                /*提交图片 结束*/
                
                $this->CgPatent->save($this->data);
                $pid = $this->data["CgPatent"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid))
                {
                    $pid=$this->CgPatent->getLastInsertId();
                    $data=array("guid"=>$pid,"event"=>"addcgpatent","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editcgpatent","usertype"=>"1");
                    $isflag=$accp->accpalert($data);	
                    $this->ProCvalue->deleteAll("pid='".$pid."'");			
                }		
                        $this->Session->setFlash("专利信息保存成功");
                                    
                /*所属产业 开始*/
                $industryids=$this->data["Project"]["industryid"];
                if($industryids)
                {
                        $objindustrys=explode(",",$industryids);
                        $objindustrys=array_unique($objindustrys);
                        $proscvalue=array();
                        foreach($objindustrys as $industry)
                        {
                            if($industry)
                            {
                                $proscvalue["ProCvalue"]["pid"]=$pid;
                                $proscvalue["ProCvalue"]["cvid"]=$industry;
                                $this->ProCvalue->save($proscvalue);
                                $this->ProCvalue->id=null;
                            }
                        }
                 }
                 /*所属产业 结束*/
                         
                 /*保存附件 开始*/
                if(!empty($_FILES['upload']))
                {
                        $uploads=$_FILES['upload'];
                        $name=$_FILES['upload']['name'];
                        $dirpath="upload/files/";
                        for($i=0;$i<count($name);$i++)
                        {
                            if($uploads["name"][$i])
                            {
                                $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                                $objAttachment["Attachment"]["pid"] = $pid;
                                $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                                $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                                $this->Attachment->save($objAttachment);
                                $this->Attachment->id=null;
                            }
                        }	
                }
                /*保存附件 结束*/
                $this->redirect(array('action'=>'showcgpatent',$this->CgPatent->id));
            }
        }
        $this->set(compact('pros_cvalues','attachments','photo'));
    }
    
    //显示一个专利信息
    function showcgpatent($id)
    {
        $this->editcgpatent($id);
        $where = "(CgProduct.is_deleted = '0' and CgProduct.patent_id = '".$id."')";
        $products = $this->CgProduct->findAll($where);
        $this->set(compact('products'));
    }
    
    //删除一个专利信息
    function delcgpatent($id)
    {
        $this->CgPatent->id = $id;
        $this->CgPatent->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delcgpatent","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("专利信息删除成功");
        $this->redirect(array('action'=>'cgpatents'));
    }
    
    //汇总所有专利转化为的产品
    function products()
    {
        $colleageid = $this->Session->read('colleageid');
        $id = $this->Session->read('patentid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/products/';
        $urlcount=0;
        
        $where = "CgProduct.is_deleted='0'";
        if($colleageid)
        {
            $where.="and CgProduct.patent_id='$id'";
        }
        $urlcount = $this->CgProduct->findCount($where);
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        $products = array();
        if ($paging['total'] > 0) 
        {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $products=$this->CgProduct->findAll($where,null, "CgProduct.created desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('products','showpage','urlcount'));
    }
    
    //编辑一个产品
    function editproduct($id = null)
    {
        $attachments = array();
        if($id)
        {
            $objproduct = $this->CgProduct->findById($id);
            $this->data = $objproduct;
            $transform_time = $objproduct["CgProduct"]["transform_time"];
            if($transform_time)
                $this->data["CgProduct"]["transform_time"] = date("Y-m-d",strtotime($transform_time));
            $attachments = $objproduct["Attachment"];
        }
        else 
        {
            if(!empty($this->data))
            {
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                    
                $patentid = $this->Session->read('patentid');
                if($patentid)
                {
                    $this->data["CgProduct"]["patent_id"] = $patentid;
                }
                $this->CgProduct->save($this->data);
                $pid = $this->data["CgProduct"]["id"];
                    App::import('Helper', 'Accp');
                    $accp = new AccpHelper();
                    if(empty($pid))
                    {
                        $pid=$this->CgProduct->getLastInsertId();
                        $data=array("guid"=>$pid,"event"=>"addproduct","usertype"=>"1");
                        $isflag=$accp->accpalert($data);
                    }else{					
                        $data=array("guid"=>$pid,"event"=>"editproduct","usertype"=>"1");
                        $isflag=$accp->accpalert($data);				
                    }		
                $this->Session->setFlash("专利信息保存成功");
                
                 /*保存附件 开始*/
                if(!empty($_FILES['upload']))
                {
                        $uploads=$_FILES['upload'];
                        $name=$_FILES['upload']['name'];
                        $dirpath="upload/files/";
                        for($i=0;$i<count($name);$i++)
                        {
                            if($uploads["name"][$i])
                            {
                                $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                                $objAttachment["Attachment"]["pid"] = $pid;
                                $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                                $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                                $this->Attachment->save($objAttachment);
                                $this->Attachment->id=null;
                            }
                        }	
                }
                /*保存附件 结束*/
                $patentid = $this->Session->read('patentid');
                $this->redirect(array('action'=>'showcgpatent',$patentid));
            }
        }
        $this->set(compact('attachments'));
    }
    
    //显示一个产品的详细信息
    function showproduct($id = null)
    {
        $this->editproduct($id);
    }		    
    
    //删除一个产品
    function delproduct($id)
    {
        $this->CgProduct->id = $id;
        $this->CgProduct->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delproduct","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("专利信息删除成功");
        $this->redirect(array('action'=>'products'));
    }
    
                                                                                                        /*高校重大设备块 开始 */
    //汇总所有的重大设备
    function equipments() 
    {
        $colleageid = $this->Session->read('colleageid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/equipments/';
        $urlcount=0;
            
        $where = "CgEquipment.is_deleted='0'";
                    
        if($colleageid)
        {
                $where.="and CgEquipment.colleage_id='$colleageid'";
        }
        $urlcount = $this->CgEquipment->findCount($where);
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        $equipments = array();
        if ($paging['total'] > 0) 
        {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $equipments=$this->CgEquipment->findAll($where,null, "CgEquipment.created desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('equipments','showpage'));
    }
    
    //编辑一个重大设备
    function editequipment($id = null)
    {
        $attachments = array();
        if($id)
        {
            $equipment = $this->CgEquipment->findById($id);
            $this->data = $equipment;
            $buy_time = $this->data["CgEquipment"]["buy_time"];
            if($buy_time)
                $this->data["CgEquipment"]["buy_time"] = date("Y-m-d",strtotime($buy_time));
            $attachments = $equipment["Attachment"];
        }
        else
        {
            if(!empty($this->data))
            {
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                
                $this->CgEquipment->save($this->data);
                $pid = $this->data["CgEquipment"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid))
                {
                    $pid=$this->CgEquipment->getLastInsertId();
                $data=array("guid"=>$pid,"event"=>"addequipment","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editequipment","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }												    
                $this->Session->setFlash("高校重大设备信息保存成功");
                
                 /*保存附件 开始*/
                if(!empty($_FILES['upload']))
                {
                    $uploads=$_FILES['upload'];
                    $name=$_FILES['upload']['name'];
                    $dirpath="upload/files/";
                    for($i=0;$i<count($name);$i++)
                    {
                        if($uploads["name"][$i])
                        {
                            $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                            $objAttachment["Attachment"]["pid"] = $pid;
                            $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                            $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                            $this->Attachment->save($objAttachment);
                            $this->Attachment->id=null;
                        }
                    }	
                }
                /*保存附件 结束*/
                $this->redirect(array('action'=>'showequipment',$this->CgEquipment->id));
            }
        }
        $this->set(compact('attachments','id'));
    }
    
    //显示一个重大设备
    function showequipment($id = null)
    {
        $this->editequipment($id);
    }
    
    //删除一个重大设备
    function delequipment($id = null)
    {
        $this->CgEquipment->id = $id;
        $this->CgEquipment->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delequipment","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("重大设备信息删除成功");
        $this->redirect(array('action'=>'equipments'));
    }
                                                                                                    /*高校重大设备块 结束*/
    
    
    //汇总所有实验室																					/*高校重点实验室 开始*/
    function labs()
    {
        $colleageid = $this->Session->read('colleageid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/labs/';
        $urlcount=0;
            
        $where = "CgLab.is_deleted='0'";
                    
         if($colleageid)
        {
                $where.="and CgLab.colleage_id='$colleageid'";
        }
        $urlcount = $this->CgLab->findCount($where);
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        $labs = array();
        if ($paging['total'] > 0) 
        {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $labs=$this->CgLab->findAll($where,null, "CgLab.created desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('labs','showpage'));
    }
    
    //编辑一个实验室
    function editlab($id = null)
    {
        $attachments = array();
        if($id)
        {
            $lab = $this->CgLab->findById($id);
            $this->data = $lab;
            $establish_time = $lab["CgLab"]["establish_time"];
            $this->data["CgLab"]["establish_time"] = date("Y-m-d",strtotime($establish_time));
            $attachments = $lab["Attachment"];
        }
        else
        {
            if(!empty($this->data))
            {
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                
                $this->CgLab->save($this->data);
                $pid = $this->data["CgLab"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid))
                {
                    $pid=$this->CgLab->getLastInsertId();
                    $data=array("guid"=>$pid,"event"=>"addlab","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editlab","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }		
                $this->Session->setFlash("高校重点实验室信息保存成功");
                
                 /*保存附件 开始*/
                if(!empty($_FILES['upload']))
                {
                    $uploads=$_FILES['upload'];
                    $name=$_FILES['upload']['name'];
                    $dirpath="upload/files/";
                    for($i=0;$i<count($name);$i++)
                    {
                        if($uploads["name"][$i])
                        {
                            $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                            $objAttachment["Attachment"]["pid"] = $pid;
                            $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                            $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                            $this->Attachment->save($objAttachment);
                            $this->Attachment->id=null;
                        }
                    }	
                }
                /*保存附件 结束*/
                $this->redirect(array('action'=>'showlab',$this->CgLab->id));
            }
        }
        $this->set(compact('attachments','id'));
    }
    
    //显示一个实验室
    function showlab($id = null)
    {
        $this->editlab($id);
    }
    
    //删除一个实验室
    function dellab($id)
    {
        $this->CgLab->id = $id;
        $this->CgLab->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"dellab","usertype"=>"1");
        $isflag=$accp->accpalert($data);	
        $this->Session->setFlash("重点实验室信息删除成功");
        $this->redirect(array('action'=>'labs'));
    }
                                                                                                    /*高校重点实验室 结束*/
    
            
                                                                                                    /*高校研究中心 开始*/
    //汇总所有研究中心
    function researchcenters()
    {
        $colleageid = $this->Session->read('colleageid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/labs/';
        $urlcount=0;
            
        $where = "CgResearchcenter.is_deleted='0'";
                    
        if($colleageid)
        {
            $where.="and CgResearchcenter.colleage_id='$colleageid'";
        }
        $urlcount = $this->CgResearchcenter->findCount($where);
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        $researchcenters = array();
        if ($paging['total'] > 0) 
        {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $researchcenters = $this->CgResearchcenter->findAll($where,null, "CgResearchcenter.created desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('researchcenters','showpage'));
    }
    
    //编辑一个研究中心
    function editresearchcenter($id = null)
    {
        $attachments = array();
        if($id)
        {
            $researchcenter = $this->CgResearchcenter->findById($id);
            $this->data = $researchcenter;
            $establish_time = $this->data["CgResearchcenter"]["establish_time"];
            if(!empty($establish_time))
                $this->data["CgResearchcenter"]["establish_time"] = date("Y-m-d",strtotime($establish_time));
            $attachments = $researchcenter["Attachment"];
        }
        else
        {
            if(!empty($this->data))
            {
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                
                $this->CgResearchcenter->save($this->data);
                $pid = $this->data["CgResearchcenter"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid))
                {
                    $pid=$this->CgResearchcenter->getLastInsertId();
                    $data=array("guid"=>$pid,"event"=>"addresearchcenter","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"editresearchcenter","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }		
                $this->Session->setFlash("高校研究中心信息保存成功");
                
                 /*保存附件 开始*/
                if(!empty($_FILES['upload']))
                {
                    $uploads=$_FILES['upload'];
                    $name=$_FILES['upload']['name'];
                    $dirpath="upload/files/";
                    for($i=0;$i<count($name);$i++)
                    {
                        if($uploads["name"][$i])
                        {
                            $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                            $objAttachment["Attachment"]["pid"] = $pid;
                            $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                            $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                            $this->Attachment->save($objAttachment);
                            $this->Attachment->id=null;
                        }
                    }	
                }
                /*保存附件 结束*/
                $this->redirect(array('action'=>'showresearchcenter',$this->CgResearchcenter->id));
            }
        }
        $this->set(compact('attachments','id'));
    }
    
    //显示一个研究中心
    function showresearchcenter($id = null)
    {
        $this->editresearchcenter($id);
    }
    
    //删除一个研究中心
    function delresearchcenter($id = null)
    {
        $this->CgResearchcenter->id = $id;
        $this->CgResearchcenter->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delresearchcenter","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("高校研究中心删除成功");
        $this->redirect(array('action'=>'researchcenters'));
    }
                                                                                                                /*高校研究中心 结束*/
              
                
      function demand()
      {
        $colleageid = $this->Session->read('colleageid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/demand/';
        $urlcount=0;
        $where="";		
        $where.="CgDemand.is_deleted='0'";
        if($colleageid)
        {
            $where.="and CgDemand.colleage_id='$colleageid'";
        }	  	    							
        $urlcount = $this->CgDemand->findCount($where);
        $paging['total'] =$urlcount;
        $showpage=0;
        $demands=array();
        if ($paging['total'] > 0) 
        {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $demands=$this->CgDemand->findAll($where,
            "`CgDemand`.`id`, `CgDemand`.`title`, `CgDemand`.`publisher`,`CgDemand`.`validity`,`CgDemand`.`created`",
            "CgDemand.modified desc",$limit,$page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('demands','showpage'));
       }
    
       function editdemand($id=null)
       {
           $industrys=$this->Codetype->getCValues($this->Constant->Industry,1);//所属产业
           $type=$this->Codetype->getCValues($this->Constant->Require_Type);
           $industrys_cvalues=array();
           $this->set(compact('id','type','industrys'));
           if($id)
           {
             $objdemand = $this->CgDemand->findById($id);
             $this->data = $objdemand;
             $industrys_cvalues=$objdemand["industrys_cvalue"];
//     		 $is_alert = "";
//     		 if(isset($objdemand["is_alert"]))
//     		 	$is_alert = $objdemand["is_alert"];
           }	
            else
            { 
                if(!empty($this->data))
                {
                    $this->CgDemand->save($this->data);
                    $gid=$this->data["CgDemand"]["id"];
                    $is_alert = $this->data["CgDemand"]["is_alert"];
                    App::import('Helper', 'Accp');
                    $accp = new AccpHelper();
                    if(empty($gid))
                    {
                        $gid=$this->CgDemand->getLastInsertId();		
    
                        /*所属产业 开始*/
                        $industryids=$this->data["Project"]["industryid"];
                        if($industryids)
                        {
                            $objindustrys=explode(",",$industryids);
                            $objindustrys=array_unique($objindustrys);
                            $industryscvalue=array();
                            foreach($objindustrys as $industry)
                            {
                                if($industry)
                                {
                                    $industryscvalue["IndustryCvalue"]["cgdemand_id"]=$gid;
                                    $industryscvalue["IndustryCvalue"]["cvid"]=$industry;
                                    $this->IndustryCvalue->save($industryscvalue);
                                    $this->IndustryCvalue->id=null;
                                }
                            }
                         }
                         /*所属产业 结束*/
                        
                        $data=array("guid"=>$gid,"event"=>"adddemand","usertype"=>"1");
                        $isflag=$accp->accpalert($data);
                        if($is_alert)
                        {
                            $data=array("guid"=>$gid,"event"=>"demand_fit_to_company","usertype"=>"1","is_alert"=>$is_alert);
                            $isflag=$accp->accpalert($data);
                        }
                        
                    }
                    else
                    {					
                        $data=array("guid"=>$gid,"event"=>"editdemand","usertype"=>"1");
                        $isflag=$accp->accpalert($data);				
                    }
                    $this->Session->setFlash('信息保存成功');
                    
                    $this->redirect(array('action'=>'demand'));           			     	        			
                 }
                 $this->data["CgDemand"]["is_alert"] = "0";
             }
             $this->set(compact("industrys_cvalues"));
         }	
                                                            
   function showdemand($id)
   {
        $this->editdemand($id);
       
   }
       
    function deldemand($id)
    {
        $this->CgDemand->id = $id;
        $this->CgDemand->saveField("is_deleted","1");
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"deldemand","usertype"=>"1");
        $isflag=$accp->accpalert($data);	
        $this->Session->setFlash("信息删除成功");
        $this->redirect(array('action'=>'demand'));	
     }
         
                                                                /*高校测试平台  开始*/
     //汇总高校的所有测试平台
     function testplatforms()
     {
        $colleageid = $this->Session->read('colleageid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/testplatforms/';
        $urlcount=0;
            
        $where = "CgTestplatform.is_deleted='0'";
                    
        if($colleageid)
        {
                $where.="and CgTestplatform.colleage_id='$colleageid'";
        }
        $urlcount = $this->CgTestplatform->findCount($where);
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        $testplatforms = array();
        if ($paging['total'] > 0) 
        {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $testplatforms = $this->CgTestplatform->findAll($where,null, "CgTestplatform.created desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('testplatforms','showpage'));
     }
     
     //编辑一个高校的测试平台
     function edittestplatform($id = null)
     {
        $attachments = array();
        if($id)
        {
            $testplatform = $this->CgTestplatform->findById($id);
            $this->Session->write("testplatform_id",$id);
            $this->data = $testplatform;
            $found_time = $this->data["CgTestplatform"]["found_time"];
            if($found_time)
                $this->data["CgTestplatform"]["found_time"] = date("Y-m-d",strtotime($found_time));
            $attachments = $testplatform["Attachment"];
        }
        else 
        {
            if(!empty($this->data))
            {
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                
                $this->CgTestplatform->save($this->data);
                $pid = $this->data["CgTestplatform"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($pid))
                {
                    $pid=$this->CgTestplatform->getLastInsertId();
                    $data=array("guid"=>$pid,"event"=>"addtestplatform","usertype"=>"1");
                    $isflag=$accp->accpalert($data);
                }else{					
                    $data=array("guid"=>$pid,"event"=>"edittestplatform","usertype"=>"1");
                    $isflag=$accp->accpalert($data);				
                }		
                $this->Session->setFlash("高校测试平台信息保存成功");
                
                 /*保存附件 开始*/
                if(!empty($_FILES['upload']))
                {
                    $uploads=$_FILES['upload'];
                    $name=$_FILES['upload']['name'];
                    $dirpath="upload/files/";
                    for($i=0;$i<count($name);$i++)
                    {
                        if($uploads["name"][$i])
                        {
                            $file_path=$actionf->upload_file($uploads,$dirpath,$i);
                            $objAttachment["Attachment"]["pid"] = $pid;
                            $objAttachment["Attachment"]["file_name"] = $uploads["name"][$i];
                            $objAttachment["Attachment"]["file_path"] = $dirpath.$file_path;
                            $this->Attachment->save($objAttachment);
                            $this->Attachment->id=null;
                        }
                    }	
                }
                /*保存附件 结束*/
                $this->redirect(array('action'=>'showtestplatform',$this->CgTestplatform->id));
            }
        }
        $this->set(compact("attachments",'id'));
     }
     
     //显示一个高校的测试平台
     function showtestplatform($id = null)
     {
        $this->edittestplatform($id);
        $where = "(CgAptitude.is_deleted = '0' and CgAptitude.testplatform_id = '".$id."')";
        $aptitudes = $this->CgAptitude->findAll($where);
        $this->set(compact('aptitudes'));
     }
     
     //删除一个高校的测试平台
     function deltestplatform($id = null)
     {
        $this->CgTestplatform->id = $id;
        $this->CgTestplatform->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"deltestplatform","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("高校测试平台删除成功");
        $this->redirect(array('action'=>'testplatforms'));
     }
     
     
     /*测试平台资质  开始*/
     //汇总一个测试平台所有的资质
     function aptitudes()
     {
        $colleageid = $this->Session->read('colleageid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/aptitudes/';
        $urlcount=0;
            
        $where = "CgAptitude.is_deleted='0'";
                    
        $testplatform_id = $this->Session->read("testplatform_id");
        if($testplatform_id)
        {
                $where.=" and CgAptitude.testplatform_id='$testplatform_id'";
        }
        $urlcount = $this->CgAptitude->findCount($where);
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        $aptitudes = array();
        if ($paging['total'] > 0) 
        {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $aptitudes = $this->CgAptitude->findAll($where,null, "CgAptitude.created desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('aptitudes','showpage'));
     }
     
     //编辑一个平台的一个资质
     function editaptitude($id = null)
     {
        $photo = array();
        if($id)
        {
            $aptitude = $this->CgAptitude->findById($id);
            $this->data = $aptitude;
            $photo = $aptitude["Photo"];
        }
        else 
        {
            if(!empty($this->data))
            {
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                
                $testplatform_id = $this->Session->read("testplatform_id");
                if($testplatform_id)
                {
                    $this->data["CgAptitude"]["testplatform_id"] = $testplatform_id;
                }
                
                /*提交图片 开始*/
                if(!empty($_FILES['AptitudePicture']))
                {
                    $uploads=$_FILES['AptitudePicture'];
                    $dirpath="upload/files/";
                    if($uploads["name"][0])
                    {
                        $file_path=$actionf->upload_file($uploads,$dirpath,0,1);
                        $objAttachments["Attachment"]["file_name"] = $uploads["name"][0];
                        $objAttachments["Attachment"]["file_path"] = $dirpath.$file_path;
                        $this->Attachment->save($objAttachments);
                        $aids=$this->Attachment->getLastInsertId();
                        $this->data["CgAptitude"]["photo_id"]=$aids;
                        $this->Attachment->id=null;
                    }
                }
                /*提交图片 结束*/
                $this->CgAptitude->save($this->data);
                $gid=$this->data["CgAptitude"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($gid)){
                $gid=$this->CgAptitude->getLastInsertId();					
                $data=array("guid"=>$gid,"event"=>"addaptitude","usertype"=>"1");
                $isflag=$accp->accpalert($data);
                }else{					
                $data=array("guid"=>$gid,"event"=>"editaptitude","usertype"=>"1");
                $isflag=$accp->accpalert($data);				
                }		
                $this->Session->setFlash("资质信息保存成功");
                $testplatform_id = $this->Session->read("testplatform_id");
                $this->redirect(array('action'=>'showtestplatform',$testplatform_id));
            }	
        }
        $this->set(compact('photo'));
     }
     
     //显示一个平台的一个资质
     function showaptitude($id = null)
     {
        $this->editaptitude($id);
     }
     
     //删除一个平台的一个资质
     function delaptitude($id = null)
     {
        $this->CgAptitude->id = $id;
        $this->CgAptitude->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delaptitude","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("高校测试平台删除成功");
        $this->redirect(array('action'=>'aptitudes'));
     }
     /*测试平台资质  结束*/
                                                            /*高校测试平台  结束*/
     
     
                                                            /*高校获奖项目  开始*/
     //汇总一个高校的所有获奖项目
     function awardprojects()
     {
        $colleageid = $this->Session->read('colleageid');
        $pagesize=10;
        $paging['show']=$pagesize;
        $paging['url'] = '/colleages/awardprojects/';
        $urlcount=0;
            
        $where = "CgAwardproject.is_deleted='0'";
                    
        if($colleageid)
        {
                $where.="and CgAwardproject.colleage_id='$colleageid'";
        }
        $urlcount = $this->CgAwardproject->findCount($where);
        $paging["total"] = $urlcount;
        $showpage = 0;
        
        $awardprojects = array();
        if ($paging['total'] > 0) 
        {
            list ($order, $limit, $page) = $this->Pagination->init("", $paging);
            $awardprojects = $this->CgAwardproject->findAll($where,null, "CgAwardproject.created desc",$limit, $page);
            if($urlcount>$pagesize)
            {
                $showpage=1;
            }
        }
        $this->set(compact('awardprojects','showpage'));
     }
     
     //编辑一个高校的获奖项目
     function editawardproject($id = null)
     {
        $photo = array();
        if($id)
        {
            $awardproject = $this->CgAwardproject->findById($id);
            $this->data = $awardproject;
            $award_time = $awardproject["CgAwardproject"]["award_time"];
            $this->data["CgAwardproject"]["award_time"] = date("Y-m-d",strtotime($award_time));
            $photo = $awardproject["Photo"];
        }
        else 
        {
            if(!empty($this->data))
            {
                App::import('Helper', 'Action');
                $actionf = new ActionHelper();
                
                /*提交图片 开始*/
                if(!empty($_FILES['AwardprojectPicture']))
                {
                    $uploads=$_FILES['AwardprojectPicture'];
                    $dirpath="upload/files/";
                    if($uploads["name"][0])
                    {
                        $file_path=$actionf->upload_file($uploads,$dirpath,0,1);
                        $objAttachments["Attachment"]["file_name"] = $uploads["name"][0];
                        $objAttachments["Attachment"]["file_path"] = $dirpath.$file_path;
                        $this->Attachment->save($objAttachments);
                        $aids=$this->Attachment->getLastInsertId();
                        $this->data["CgAwardproject"]["photo_id"]=$aids;
                        $this->Attachment->id=null;
                    }
                }
                /*提交图片 结束*/
                $this->CgAwardproject->save($this->data);
                $gid=$this->data["CgAwardproject"]["id"];
                App::import('Helper', 'Accp');
                $accp = new AccpHelper();
                if(empty($gid)){
                $gid=$this->CgAwardproject->getLastInsertId();					
                $data=array("guid"=>$gid,"event"=>"addawardproject","usertype"=>"1");
                $isflag=$accp->accpalert($data);
                }else{					
                $data=array("guid"=>$gid,"event"=>"editawardproject","usertype"=>"1");
                $isflag=$accp->accpalert($data);				
                }								
                $this->Session->setFlash("获奖项目信息保存成功");
                $this->redirect(array('action'=>'showawardproject',$this->CgAwardproject->id));
            }
        }
        $this->set(compact('photo','id'));
     }
     
     //显示一个高校的获奖项目
     function showawardproject($id = null)
     {
        $this->editawardproject($id);
     }
     
     //删除一个高校的获奖项目
     function delawardproject($id = null)
     {
        $this->CgAwardproject->id = $id;
        $this->CgAwardproject->saveField("is_deleted",'1');
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("guid"=>$id,"event"=>"delawardproject","usertype"=>"1");
        $isflag=$accp->accpalert($data);
        $this->Session->setFlash("高校获奖项目删除成功");
        $this->redirect(array('action'=>'awardprojects'));
     }
         
                                                                 /*高校获奖项目  结束*/
         
    
    function dourl($userid,$id)
    {
        $urlpath = base64_decode($_GET["urlpath"]);
        $userid = base64_decode($userid);
        $id = base64_decode($id);
        App::import('Helper', 'Accp');
        $accp = new AccpHelper();
        $data=array("userid"=>$userid);
        $logindata=$accp->accplogin($data);
        if($logindata['result'])
        {
            $this->Session->write('pwd', $this->data['User']['password']);
            $this->Session->write('User', $logindata);
            
            $data=array("isadmin"=>"1","userid"=>"0","usertype"=>"1");
            $objusers=$accp->accpuser($data);
            $this->Session->write('UserList',$objusers);
            $this->loadModel("SearchCompany");
            $objcolleage=$this->Colleage->findById($id,"`Colleage`.`colleage_name`");
            $this->Session->write('colleageid', $id);
            $this->Session->write('colleagename', $objcolleage["Colleage"]["colleage_name"]);
            $this->redirect($urlpath);
        }
    }
    
    //打开页面前执行的方法
    function beforeFilter()
    {
        parent::beforeFilter();
        $language = 'chn';
        $this->Session->write('Config.language', $language);
        $user=$this->Session->read('User');
        if (!$user){
            $isflag=1;
            if($this->action=="dourl"){
                $isflag=0;
            }
            if($isflag){
            $this->redirect('/users/login');}
        }else{
            if($user['cgid'] && $this->action=="index"){
                $this->redirect('/colleages/showcolleageinfo/'.$user['cgid']);
                exit();
            }
        }
    }
    //打开页面后执行的方法
    function afterFilter()
    {
        
    }
}
    
    
    
?>